package io.github.codelifeleno.jdbrelease.execute;

import cn.hutool.core.io.resource.ResourceUtil;
import io.github.codelifeleno.jdbrelease.config.JDBReleaseConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

import static org.junit.jupiter.api.Assertions.*;

class DBScriptConfigInitTest {

    JDBReleaseConfig jdbReleaseConfig = null;

    @BeforeEach
    void setUp() {
        jdbReleaseConfig = new JDBReleaseInit().initConfig(ResourceUtil.getResourceObj("F:\\Datas\\Workspace\\GitOnlineProjects\\JDBRelease\\commons\\src\\test\\resources\\JDBReleaseConfig.xml"));
    }

    @Test
    void init() throws URISyntaxException, IOException {
        DBScriptConfigInit dbScriptConfigInit = new DBScriptConfigInit();
        assertNotNull(dbScriptConfigInit);
        dbScriptConfigInit.init(jdbReleaseConfig);

        dbScriptConfigInit.getDbScriptConfigMap().forEach((k, v) -> {

            System.out.print(k);
            System.out.print("\t");
            System.out.print(k.toString());
            System.out.print("\t");
            System.out.println(v);

            assertNotNull(v);
            assertNotNull(v.getComments());
            assertNotNull(v.getComments().getSingleLine());
            assertNotNull(v.getComments().getSingleLine().getPrefixes());
            assertNotEquals(0, v.getComments().getSingleLine().getPrefixes().size());
            assertNotNull(v.getComments().getBlocks());
            assertNotEquals(0, v.getComments().getBlocks().size());
            assertNotNull(v.getSeparator());
            assertNotNull(v.getSeparator().getSimple());
            assertNotNull(v.getSeparator().getEof());
            assertTrue(";".equals(v.getSeparator().getSimple()) || "//".equals(v.getSeparator().getSimple()));

            assertArrayEquals(new String[]{"--", "#"}, v.getComments().getSingleLine().getPrefixes().toArray());

        });

        System.out.println(dbScriptConfigInit.getDbScriptConfigMap().containsKey(new File("F:\\Datas\\Workspace\\GitOnlineProjects\\JDBRelease\\commons\\target\\test-classes\\db\\changelog")));
    }
}